package lex.dm.id3;

public class ID3Utils {
	/**
	 * ����ֵ�صļ��� Info(T)=(i=1...k)pi*log��2��pi
	 * 
	 * @param x
	 * @param total
	 * @return double
	 */
	public static double sigma(int x, int total) {
		if (x == 0) {
			return 0;
		}
		double x_pi = getPi(x, total);
		return -(x_pi * log2(x_pi));
	}

	/**
	 * log(2, x)
	 * 
	 * @param x
	 * @return double
	 */
	public static double log2(double x) {
		return Math.log(x) / Math.log(2);
	}

	/**
	 * pi�ǵ�ǰ������Գ��ֵĸ��ʣ�=���ִ���/����
	 * 
	 * @param x
	 * @param total
	 * @return double
	 */
	public static double getPi(int x, int total) {
		return x * 1.0D / total;
	}
}
